﻿@model DeliveryManage.Model.Pro_ShopGoods

@{
    Layout = null;
    DeliveryManage.Models.ReturnMsgModel returnMsg = ViewBag.ReturnMsgModel;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>产品编辑</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="~/Content/font.css">
    <link rel="stylesheet" href="~/Content/framemain.css">
    <link href="~/Content/icon/iconfont.css" rel="stylesheet" />
    <link href="~/Content/style.css" rel="stylesheet" />
    <link rel="stylesheet" href="~/Content/layui/css/modules/layer/default/layer.css" />
    <script type="text/javascript" src="~/Scripts/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="~/Content/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="~/Scripts/framemain.js"></script>
    <script type="text/javascript" src="~/Scripts/laymain.js"></script>
    <script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
    <script type="text/javascript" src="~/Scripts/uploader.js"></script>
    <script type="text/javascript" src="~/Scripts/webuploader/webuploader.min.js"></script>

    <style>
        .layui-layer-contents {
            text-align: center;
            position: absolute;
            padding: 25%;
            font-size: 1rem;
            text-align:left;
        }

        .layui-form-item .layui-input-inline {
            width: 300px;
        }
        .layui-input {
            padding: 10px;
        }
        .text-path {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            direction: rtl;
            text-align: left;
            width: 70%;
            float: left;
        }
        .img-view {
            padding:10px;
        }
            .img-view img {
                width: 100px;
                height: 100px;
                border-radius: 5px;
                border: 1px solid #e2e2e2;
            }
        .photo-list ul {
            margin:0px;
        }
        .tab-content dl dd {
            margin:0px;
        }
        .display {
            display:none;
        }
    </style>
    <script type="text/javascript">
        $(function () {
            //操作提示
            if(@returnMsg.code== 400){
                layer.alert('@returnMsg.msg', { icon: 5, title: '提示' }, function (index) {
                })
            }
            $(document).ready(function () {
                $("#myfrom").submit(function () {
                    var data = $(this).serialize();
                    layer.confirm('确认提交吗?', { icon: 3, title: '提示' }, function (index) {
                        $.ajax({
                            type: "POST",
                            url: "/Goods/ProductEdit",
                            data: data,
                            success: function (obj) {
                                if (obj.status == true) {
                                    layer.msg(obj.msg, { icon: 6, title: '提示' }, function (index) {
                                        window.parent.window.location.href = '/Goods/ProductList';
                                    });
                                } else {
                                    layer.confirm(obj.msg, { icon: 5, title: '提示' }, function (index) {
                                        layer.close();
                                        location.reload();
                                    });
                                }
                            }
                        })
                        layer.close();
                    });
                    return false;

                })

                //初始化文件上传控件
                $(".selectfile").InitUploader({ btntext: "上传封面", sendurl: "../../Tools/upload_ajax.ashx", filetypes: "png,jpg,jepg", filesize: 10485760, swf: "~/scripts/webuploader/uploader.swf" });
            })
        });
    </script>

</head>
<body>
    <form id="myfrom" class="tab-content layui-form" action="" lay-filter="example">

        @{
            if (returnMsg.code == 200)
            {
                @Html.HiddenFor(m => m.Id)
                @Html.Hidden("AddOrEdit", (string)ViewBag.AddOrEdit)
                <div class="layui-fluid">
                    <div class="layui-row">
                        <div class="layui-form-item">
                            <label class="layui-form-label">
                                <span class="x-red">*</span>套餐编码
                            </label>
                            <div class="layui-input-inline">
                                @Html.TextBoxFor(m => m.Code, new { @datatype = "s2-10", @class = "layui-input", @sucmsg = " ", placeholder = "请输入套餐编码" })
                            </div>
                            <div class="layui-form-mid layui-word-aux">
                                <span class="x-red">*套餐编码唯一性，可编辑，默认随机生成</span>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">
                                <span class="x-red">*</span>套餐名称
                            </label>
                            <div class="layui-input-inline">
                                @Html.TextBoxFor(m => m.Name, new { @datatype = "s2-10", @class = "layui-input", @sucmsg = " ", placeholder = "请输入套餐名称" })
                            </div>
                            <div class="layui-form-mid layui-word-aux">
                                <span class="x-red">*请输入套餐名称</span>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">
                                <span class="x-red">*</span>封面图
                            </label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input text-path upload-path" readonly="readonly" id="Picture" name="Picture" value="@Model.Picture" placeholder="XX.png/XX.jpg/XX.jpeg" />
                                <div class="upload-box upload-img selectfile"></div>
                                <div class="photo-list">
                                    <ul>
                                        @{
                                            if (!string.IsNullOrEmpty(Model.Picture))
                                            {
                                                <div class="img-view">
                                                    <img src="@Model.Picture" />
                                                </div>
                                            }
                                        }
                                    </ul>
                                </div>
                            </div>
                            <div class="layui-form-mid layui-word-aux">
                                <span class="x-red">请选择图片文件并上传，且类型如：.png、jpg、.jpeg</span>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">
                                <span class="x-red">*</span>排序编号
                            </label>
                            <div class="layui-input-inline">
                                @Html.TextBoxFor(m => m.SortBy, new { @datatype = "n", @class = "layui-input", @sucmsg = " " })
                            </div>
                            <div class="layui-form-mid layui-word-aux">
                                <span class="x-red">*排序方式，数值越小，排名靠前</span>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">
                                <span class="x-red">*</span>成本价格
                            </label>
                            <div class="layui-input-inline">
                                @Html.TextBoxFor(m => m.CostPrice, new { @datatype = "s2-10", @class = "layui-input", @sucmsg = " ", placeholder = "请输入成本价格" })
                            </div>
                            <div class="layui-form-mid layui-word-aux">
                                <span class="x-red">*成本价格必须为大于0的数字</span>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">
                                <span class="x-red">*</span>市场价格
                            </label>
                            <div class="layui-input-inline">
                                @Html.TextBoxFor(m => m.NormalPrice, new { @datatype = "s2-10", @class = "layui-input", @sucmsg = " ", placeholder = "请输入市场价格" })
                            </div>
                            <div class="layui-form-mid layui-word-aux">
                                <span class="x-red">*市场价格必须为大于0的数字</span>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">
                                <span class="x-red">*</span>套餐类型标签
                            </label>
                            <div class="layui-input-inline">
                                <input type="radio" name="labeType" value="false" lay-filter="labeType" lay-verify="required" title="标准" @(Model.Lable == false ? "checked=\"checked\"" : "")>
                                <input type="radio" name="labeType" value="true" lay-filter="labeType" lay-verify="required" title="促销" @(Model.Lable == true ? "checked=\"checked\"" : "")>
                            </div>
                            <div class="layui-form-mid layui-word-aux">
                                <span class="x-red">*</span>
                            </div>
                        </div>
                        <div class="layui-form-item @(Model.Lable != false?"display":"")" id="Div_CounterPrices">
                            <label class="layui-form-label">
                                <span class="x-red">*</span>正常出售价格
                            </label>
                            <div class="layui-input-inline">
                                @Html.TextBoxFor(m => m.CounterPrices, new { @datatype = "s2-10", @class = "layui-input", @sucmsg = " ", placeholder = "请输入市场价格" })
                            </div>
                            <div class="layui-form-mid layui-word-aux">
                                <span class="x-red">*出售价格必须为大于0的数字</span>
                            </div>
                        </div>
                        <div class="layui-form-item @(Model.Lable != true?"display":"")" id="Div_ActivityPrices">
                            <label class="layui-form-label">
                                <span class="x-red">*</span>活动价格
                            </label>
                            <div class="layui-input-inline">
                                @Html.TextBoxFor(m => m.ActivityPrices, new { @datatype = "s2-10", @class = "layui-input", @sucmsg = " ", placeholder = "请输入活动价格" })
                            </div>
                            <div class="layui-form-mid layui-word-aux">
                                <span class="x-red">*活动价格必须为大于0的数字</span>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">
                                <span class="x-red">*</span>销售提成
                            </label>
                            <div class="layui-input-inline">
                                @Html.TextBoxFor(m => m.Commission, new { @datatype = "s2-10", @class = "layui-input", @sucmsg = " ", placeholder = "请输入销售提成奖励" })
                            </div>
                            <div class="layui-form-mid layui-word-aux">
                                <span class="x-red">*该奖励设置时，表示卖出一单的固定奖励</span>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">
                                <span class="x-red">*</span>套餐规格
                            </label>
                            <div class="layui-input-inline" style="width:500px;">
                                <table class="layui-table layui-form">
                                    <thead>
                                        <tr>
                                            <th style="width:25%">套餐数量</th>
                                            <th style="width:25%">商品数(瓶)</th>
                                            <th style="width:25%">套餐规格</th>
                                            <th style="width:25%">剩余库存</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                            <td>
                                                @Html.TextBoxFor(m => m.CalcSpec, new { @datatype = "s2-10", @class = "layui-input", @sucmsg = " ", placeholder = "请输入套餐数量规格" })
                                            </td>
                                            <td>
                                                <input type="number" id="SpecNum" name="SpecNum" class="layui-input" placeholder="单个套餐包含的产品数量" value="@Model.SpecNum" min="0" />
                                            </td>
                                            <td>
                                                <div class="layui-inline layui-show-xs-block" style="width:100px">
                                                    @Html.DropDownListFor(m => m.SpecUnit, ViewData["SpecUnitList"] as SelectList, new { @class = "layui-input layui-select", @lay_filter = "specUnit" })
                                                </div>
                                            </td>
                                            <td>
                                                <input type="number" id="Stock" name="Stock" class="layui-input" placeholder="请输入套餐库存" value="@Model.Stock" min="0" />
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">
                                <span class="x-red">*</span>是否上架
                            </label>
                            <div class="layui-input-inline">
                                <input type="checkbox" checked="" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="是|否">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">
                                <span class="x-red"></span>
                            </label>
                            <div class="layui-input-inline">
                                <input id="btnSubmit" name="btnSubmit" type="submit" value="保存信息" class="layui-btn" />
                            </div>
                        </div>
                    </div>
                </div>
            }
            else
            {
                <p id="" class="layui-layer-contents">
                    @returnMsg.msg
                </p>
            }
        }

        <script>    
            layui.use('form', function () {
                var form = layui.form;

                // 监听radio点击事件
                form.on('radio(labeType)', function (data) {
                    //console.log(data.value); // 被点击的radio的value值
                    // 在这里编写你的业务逻辑
                    if (data.value == 'true') {
                        $('#Div_ActivityPrices').removeClass("display");
                        $('#Div_CounterPrices').addClass("display");
                    } else
                    {
                        $('#Div_CounterPrices').removeClass("display");
                        $('#Div_ActivityPrices').addClass("display");
                    }
                        
                });
            });
        </script>
    </form>
</body>
</html>
